﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infrastructure.Aspect; 
using Infrastructure.WpfClient;
using Microsoft.Practices.Unity;
using Skynet.MeshFoundation.SkyNetLibraryDataSetTableAdapters;
using Microsoft.Practices.Composite.Presentation.Commands;
using Skynet.MeshFoundation.Services;
namespace Skynet.MeshAdministration.Views.MainExamCategory
{
    public class MainExamCategoryPresenter : Infrastructure.WpfClient.Views.Master.MasterPresenter<IMainExamCategoryView>
    {
        [Dependency]
        public ISyncService SyncService { get; set; }
        public Skynet.MeshFoundation.SkyNetLibraryDataSet Model { get; set; }
        public ExamCategoriesTableAdapter ExamCategoriesAdapter { get; set; }
        public DelegateCommand<object> SyncCommand { get; set; }
                
        public MainExamCategoryPresenter(IUnityContainer container) :  base(container)
        {
            this.SyncCommand = new DelegateCommand<object>(OnSyncCommandCommand);
        }
        protected void OnSyncCommandCommand(object target)
        {
            this.ExamCategoriesAdapter.Update(this.Model.ExamCategories);
            this.SyncService.SyncApplication();            

        }                
        public override void OnViewReady()
        {
            Model = new MeshFoundation.SkyNetLibraryDataSet();
            ExamCategoriesAdapter = new ExamCategoriesTableAdapter();            
            ExamCategoriesAdapter.Fill(Model.ExamCategories);   
            this.Model.ExamCategories.ExamCategoriesRowChanged += new MeshFoundation.SkyNetLibraryDataSet.ExamCategoriesRowChangeEventHandler(ExamCategories_ExamCategoriesRowChanged);
            this.InvokePropertyChanged("Model");
            
        }

   
        void ExamCategories_ExamCategoriesRowChanged(object sender, MeshFoundation.SkyNetLibraryDataSet.ExamCategoriesRowChangeEvent e)
        {
            switch (e.Action)
            {
                case System.Data.DataRowAction.Add:                                       
                    this.ExamCategoriesAdapter.Update(this.Model.ExamCategories); 
                    break;
                case System.Data.DataRowAction.Change:
                    break;
                case System.Data.DataRowAction.ChangeCurrentAndOriginal:
                    break;
                case System.Data.DataRowAction.ChangeOriginal:
                    break;
                case System.Data.DataRowAction.Commit:
                    break;
                case System.Data.DataRowAction.Delete:
                    break;
                case System.Data.DataRowAction.Nothing:
                    break;
                case System.Data.DataRowAction.Rollback:
                    break;
                default:
                    break;
            }
     

        }
    }
}
